package com.hospital.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;
import com.hospital.util.MD5;

@WebServlet("/RegServlet")
public class RegServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String account = request.getParameter("account").trim();
		String pswd = request.getParameter("pswd").trim();
		String md5password = MD5.MD5(pswd);
		String sex = request.getParameter("sex");
		String birthday = request.getParameter("birthday");
		String address = request.getParameter("address");
		String tel = request.getParameter("tel");
		String sql = "insert into t_user_info(account, pswd, root, sex, birthday, address, tel, money, deptId, school, education, departmentName) values('"
		+ account + "', '" + md5password + "','" + 0 + "', '" + sex + "', '" + birthday + "', '" + address + "', '" + tel + "', '" + 0 + "', '"+ 0 + "', '" + "null" +"', '" + "null" + "', '"+ "null" +"')";
		boolean b = DbUtil.add_modify(sql);
		if(b){
			request.setAttribute("rs", "注册成功，请登录。");
			request.getRequestDispatcher("/reg.jsp").forward(request, response);
		}else{
			request.setAttribute("rs", "注册失败，请重注册。");
			request.getRequestDispatcher("/reg.jsp").forward(request, response);
		}
	}
}
